package com.tongqin.distributed;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author yuantongqin
 * @date 2018/7/9 下午3:47
 */
public class RpcServer {

    private ExecutorService executorService = Executors.newCachedThreadPool();

    public void publisher(final Object server,int port){

        ServerSocket serverSocket = null;
        try {
            //启动服务监听
            serverSocket = new ServerSocket(port);
            //循环拿到服务

            while (true){

                Socket socket = serverSocket.accept();
                executorService.submit(new ProcessorHandler(socket,server));
            }


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(serverSocket != null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
